<?php

class m_class extends MY_Controller {


	function __construct()
	{
		parent::__construct();
		$this->load->helper('form');
		$this->load->model('class_model');	
	}
	
	
	// 显示：分类管理
	function index()
	{
		//$this->m_manage->islogin();		// check登陆状态
		$data = $this->data_config;
	
		//  gaoji_productsort 为表名
		$vdata=$this->class_model->getsort('jiaju_class');
		
		// 取出子分类
		$getchild=$this->class_model->getchildren($vdata,1,0);
		
		$data['child']=$getchild;
	
		$this->load->view('admin/m_class_view',$data);
	}
	
	
	// ------------------------------------------------------------------------
	/**
		* 测试
	*/
	function getmicrotime()  
	{  
     	list($usec, $sec) = explode(" ",microtime());  
    	return ((float)$usec + (float)$sec);  
	} 
	
	public function testreturn()
	{
	
		$time_start = $this->getmicrotime();  
	$vdata=$this->class_model->getsort('jiaju_areadetail');
		$getchild=$this->class_model->getchildren2($vdata,1,0);
		header("content-type:text/html;charset=utf-8");
		foreach ($getchild as $value):	
			echo $value->region_id.'-'.$value->region_name."<br />";
		endforeach;
	$time_end = $this->getmicrotime();  
printf ("[页面执行时间: %.2f毫秒]\n\n",($time_end - $time_start)*1000); 
	}
	
	
	
	
	// 显示： 添加分类
	function classadd()
	{
		$data = $this->data_config;  // 加载config
		$data["vtitle"] = 1;
		//	按层次读取分类
		$vdata=$this->class_model->getsort('jiaju_class');
		$getchild=$this->class_model->getchildren($vdata,1,0);
		
		$tempdata = array();
		$tempdata[1] = '一级分类';
		
		$myvalue='';
		foreach ($getchild as $value): 
				for($i=0;$i<$value->deep;$i++)
				{
					$myvalue .="&nbsp&nbsp&nbsp|-";
				}
			$myvalue .= $value->classname;	
			$tempdata[$value->classid]=$myvalue;
			$myvalue='';
        endforeach;
		form_dropdown('classtopid', $tempdata);
		
		$data["form_open"] = form_open('m_class/doaddclass');
		$data["classid"] = '';
		
		$js = 'style="width:200px;"';
		$data["classtopid"]= form_dropdown('classtopid',$tempdata,'0',$js);
		
		$tdata = array(
			'name'        => 'classname',
			'id'          => 'classname',
			'style'       => 'width:300px',
		);

		$data["classname"]= form_input($tdata);
		$data["mysubmit"] =  form_submit('mysubmit', '提交');
		$data["form_close"] = form_close();	
		$this->load->view('admin/m_classadd_view',$data);
	}
	

	// 显示： 添加分类（域名）
	function classadd2()
	{
		$data = $this->data_config;  // 加载config
		$data["vtitle"] = 1;
		//	按层次读取分类
		$vdata=$this->class_model->getsort('jiaju_areadetail');
		$getchild=$this->class_model->getchildren2($vdata,1,0);
		
		$tempdata = array();
		$tempdata[0] = '一级分类';
		
		$myvalue='';
		foreach ($getchild as $value): 
				for($i=0;$i<$value->deep;$i++)
				{
					$myvalue .="&nbsp&nbsp&nbsp|-";
				}
			$myvalue .= $value->region_name;	
			$tempdata[$value->region_id]=$myvalue;
			$myvalue='';
        endforeach;
		form_dropdown('classtopid', $tempdata);
		
		$data["form_open"] = form_open('m_class/doaddclass');
		$data["classid"] = '';
		
		$js = 'style="width:200px;"';
		$data["classtopid"]= form_dropdown('classtopid',$tempdata,'0',$js);
		
		$tdata = array(
			'name'        => 'classname',
			'id'          => 'classname',
			'style'       => 'width:300px',
		);

		$data["classname"]= form_input($tdata);
		$data["mysubmit"] =  form_submit('mysubmit', '提交');
		$data["form_close"] = form_close();	
		$this->load->view('admin/m_classadd_view',$data);
	}
	


	// 操作：分类添加
	function doaddclass()
	{
		$data["classtopid"] 		= $_POST['classtopid'];
		$data["classname"]			= $_POST['classname'];
		if(($this->class_model->addclass($data))==1){
			$sdata["message"] = "恭喜您，操作成功!";
			$sdata["url"] = $this->data_config['base_header']."/m_class/classadd";
			$this->shownotice($sdata);
		}		
		
	}

	// 显示：分类修改
	function updateclass($classid)
	{
		$data = $this->data_config;  // 加载config
		$data["vtitle"] = 2;
		//	按层次读取分类
		$vdata=$this->class_model->getsort('jiaju_class');
		$getchild=$this->class_model->getchildren($vdata,1,0);
		
		$tempdata = array();
		$tempdata[1] = '一级分类';
		
		$myvalue='';
		foreach ($getchild as $value): 
			for($i=0;$i<$value->deep;$i++)
			{
				$myvalue .="&nbsp&nbsp&nbsp|-";
			}
		$myvalue .= $value->classname;	
		$tempdata[$value->classid]=$myvalue;
		$myvalue='';
        endforeach;
		form_dropdown('classtopid', $tempdata);
		
		$data["form_open"] = form_open('m_class/doupdateclass');
		$data["classid"]=form_hidden('classid',$classid);
		
		$js = 'style="width:200px;"';
		$data["classtopid"]= form_dropdown('classtopid',$tempdata,$this->class_model->getclasstopid($classid),$js);
		
		$tdata = array(
			'name'        => 'classname',
			'id'          => 'classname',
			'style'       => 'width:300px',
			'value'       => $this->class_model->getclassname($classid)
		);

		$data["classname"]= form_input($tdata);
		$data["mysubmit"] =  form_submit('mysubmit', '提交');
		$data["form_close"] = form_close();	
		$this->load->view('admin/m_classadd_view',$data);
	}


	// 操作：分类修改
	function doupdateclass()
	{
		$data["classid"] 			= $_POST['classid'];
		$data["classtopid"] 		= $_POST['classtopid'];
		$data["classname"]			= $_POST['classname'];
		if(($this->class_model->doupdateclass($data))==1){
			$sdata["message"] = 1;
			$sdata["url"] = $this->data_config['base_header']."/m_class";
			$this->shownotice($sdata);
		}		
	}
	
	// 提示显示页面
	function shownotice($data)
	{
		$this->load->view('admin/m_shownote_view',$data);
	}





		
}











